package com.dmap.analysispoint.controller.background;


import com.dmap.analysispoint.bo.NameAndValueBo;
import com.dmap.analysispoint.controller.background.param.CountParam;
import com.dmap.analysispoint.service.DataBoardService;
import com.dmap.base.constants.Constant;
import com.dmap.base.vo.BaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * \* @author:zhouhao
 * \* Date:10/05/2018
 * \* Description:
 * \*
 */
@Api(value = "数据看板", description = "background/数据看板")
@Controller
@RequestMapping(value = "/background/dmap-analysis-point-server/v2/")

public class DataBoardAnalysisController {

    @Resource
    private DataBoardService dataBoardService;

    @ResponseBody
    @ApiOperation(value = "数据看板部分新增用户、活跃用户模块的分析",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、设备类型、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为当天零点时间戳、当前查询时间的时间戳\n" +
                    "2.返回符合查询条件的数据看板部分新增用户、活跃用户模块的信息和数据")
    @RequestMapping(value = "dataBoardAnalysisList", method = RequestMethod.POST)
    public BaseVo dataBoardAnalysisList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<List> dataBoardAnalysisList = dataBoardService.dataBoardAnalysisList(param);
        baseVo.setData(dataBoardAnalysisList);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "数据看板部分APP版本TOP分析",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、设备类型、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为当天零点时间戳、当前查询时间的时间戳\n" +
                    "2.返回符合查询条件的数据看板部分APP版本TOP分析的信息和数据")
    @RequestMapping(value = "countAppVersionList", method = RequestMethod.POST)
    public BaseVo countAppVersionList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<NameAndValueBo> countAppVersionList = dataBoardService.countAppVersionList(param);
        List<String> appVersionNameList = new ArrayList<>();
        for (NameAndValueBo nameAndValueBo :countAppVersionList) {
            appVersionNameList.add(nameAndValueBo.getName());
        }
        List<List> list = new ArrayList<>();
        list.add(0,countAppVersionList);
        list.add(1,appVersionNameList);
        baseVo.setData(list);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "数据看板部分固件版本TOP分析",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、设备类型、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为当天零点时间戳、当前查询时间的时间戳\n" +
                    "2.返回符合查询条件的数据看板部分固件版本TOP分析的信息和数据")
    @RequestMapping(value = "countFirmwareVersionList", method = RequestMethod.POST)
    public BaseVo countFirmwareVersionList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<NameAndValueBo> countFirmwareVersionList = dataBoardService.countFirmwareVersionList(param);
        List<String> firmwareVersionNameList = new ArrayList<>();
        for (NameAndValueBo nameAndValueBo :countFirmwareVersionList) {
            firmwareVersionNameList.add(nameAndValueBo.getName());
        }
        List<List> list = new ArrayList<>();
        list.add(0,countFirmwareVersionList);
        list.add(1,firmwareVersionNameList);
        baseVo.setData(list);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "数据看板部分手机版本TOP分析",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、设备类型、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为当天零点时间戳、当前查询时间的时间戳\n" +
                    "2.返回符合查询条件的数据看板部分手机版本TOP分析的信息和数据")
    @RequestMapping(value = "countPhoneVersionList", method = RequestMethod.POST)
    public BaseVo countPhoneVersionList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<NameAndValueBo> countPhoneVersionList = dataBoardService.countPhoneVersionList(param);
        List<String> phoneVersionNameList = new ArrayList<>();
        for (NameAndValueBo nameAndValueBo :countPhoneVersionList) {
            phoneVersionNameList.add(nameAndValueBo.getName());
        }
        List<List> list = new ArrayList<>();
        list.add(0,countPhoneVersionList);
        list.add(1,phoneVersionNameList);
        baseVo.setData(list);
        return baseVo;
    }
}
